Skip to content

KAFKA-14365: Extract common logic from Fetcher#13425

Merged
guozhangwang merged 2 commits into
apache:trunkfrom
kirktrue:KAFKA-14365-extract-abstractfetcher
Mar 24, 2023
Merged

KAFKA-14365: Extract common logic from Fetcher#13425
guozhangwang merged 2 commits into
apache:trunkfrom
kirktrue:KAFKA-14365-extract-abstractfetcher

Conversation

@kirktrue

@kirktrue kirktrue commented Mar 20, 2023

Copy link
Copy Markdown
Contributor

The Fetcher class is used internally by the KafkaConsumer to fetch records from the brokers. There is ongoing work to create a new consumer implementation with a significantly refactored threading model. The threading refactor work requires a similarly refactored Fetcher.

This task includes refactoring Fetcher by extracting out some common logic to allow forthcoming implementations to leverage it.

  1. Extract logic from Fetcher into AbstractFetch
  2. Introduce FetchConfig as a concise way to delineate incoming configuration from state
  3. Formalized the defaults in CommonClientConfigs and ConsumerConfig to be accessible elsewhere

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@C0urante

Copy link
Copy Markdown
Contributor

fetch

Extract logic from Fetcher into AbstractFetcher.

Also introduce FetchConfig as a more concise way to delineate state from
incoming configuration.

Formalized the defaults in CommonClientConfigs and ConsumerConfig to be
accessible elsewhere.
@kirktrue

Copy link
Copy Markdown
Contributor Author

@guozhangwang @hachikuji @rajinisivaram @philipnee This is ready for a review from whomever has the time.

@guozhangwang guozhangwang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. Except the question for synchronizing the super's functions I think we can move forward to merge.

config.getBoolean(ConsumerConfig.THROW_ON_FETCH_STABLE_OFFSET_UNSUPPORTED),
config.getString(ConsumerConfig.CLIENT_RACK_CONFIG));
}
FetchConfig<K, V> fetchConfig = new FetchConfig<>(config, keyDeserializer, valueDeserializer, isolationLevel);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement, +1!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FetchConfig<K, V> fetchConfig = new FetchConfig<>(config, keyDeserializer, valueDeserializer, isolationLevel);
FetchConfig<K, V> fetchConfig = new FetchConfig<>(config, this.keyDeserializer, this.valueDeserializer, isolationLevel);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirktrue , these should be this.keyDeserializer and this.valueDeserializer. Otherwise the original values may be null and will cause an NPE on line 300 of CompletedFetch.java

Comment thread clients/src/main/java/org/apache/kafka/clients/consumer/internals/Fetcher.java Outdated
*
* @return true if there are completed fetches, false otherwise
*/
boolean hasCompletedFetches() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a quick browse on this class assuming that all the logic are not changed, i.e. mostly copy-paste here except the FetchConfig wrapping. Please LMK otherwise and I will give it a deeper look.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally did my best to keep the code I moved from Fetcher into AbstractFetch identical. There was some minor refactoring which could technically introduce bugs.

@guozhangwang

Copy link
Copy Markdown
Contributor

I've checked the failed tests, which are irrelevant.

@guozhangwang

Copy link
Copy Markdown
Contributor

LGTM, merged to trunk.

@guozhangwang
guozhangwang merged commit a325262 into apache:trunk Mar 24, 2023
@rayokota

rayokota commented Mar 25, 2023

Copy link
Copy Markdown
Contributor

@guozhangwang , @kirktrue , this PR is causing NPEs downstream. I've added a comment above that indicates the problematic lines. Thanks.

@kirktrue
kirktrue deleted the KAFKA-14365-extract-abstractfetcher branch March 25, 2023 23:17
@philipnee philipnee added KIP-848 The Next Generation of the Consumer Rebalance Protocol ctr Consumer Threading Refactor (KIP-848) labels May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ctr Consumer Threading Refactor (KIP-848) KIP-848 The Next Generation of the Consumer Rebalance Protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants